package com.wzk

import java.io.{ByteArrayInputStream, ByteArrayOutputStream, ObjectInputStream, ObjectOutputStream}

import org.roaringbitmap.RoaringBitmap

object RoaringBitmapDemo {
  def main(args: Array[String]): Unit = {
    val bit1 = RoaringBitmap.bitmapOf(1, 3, 5, 6, 7, 9)
    val bit2 = RoaringBitmap.bitmapOf(2, 4, 6, 9)
    println(bit1)
    println(bit2)
    println(bit1.getCardinality)
    println(bit2.getCardinality)
    bit1.or(bit2)
    println(bit1)
    println(bit1.getCardinality)

    println("**********************")
    //将bitmap对象序列化
    val baout = new ByteArrayOutputStream()
    val oos = new ObjectOutputStream(baout)
    oos.writeObject(bit1)
    val arrBit = baout.toByteArray
    //反序列化
    val in = new ByteArrayInputStream(arrBit)
    val ois = new ObjectInputStream(in)
    val bitmap = ois.readObject().asInstanceOf[RoaringBitmap]
    println(bitmap)
    ois.close()
    oos.close()

  }
}
